﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Text.RegularExpressions;

namespace ApiDoc
{
    /// <summary>
    /// Extensions for MarkupString.
    /// </summary>
    public static class MarkupStringExtensions_PlainText
    {
        /// <summary>
        /// Returns the plain-text version of <paramref name="s"/>.
        /// </summary>
        /// <returns></returns>
        public static string ToPlainText(this MarkupString s)
        {
            var manager = s.GetManager();
            var member = s.GetOwner();

            string text = manager.CreateDocumentationStringWithLinks(s.ToString(), member);

            // Strip tags.
            text = WebUtility.HtmlDecode(Regex.Replace(text, "<[^>]*(>|$)", String.Empty));

            return text;
        }
    }
}
